#!/usr/bin/env python3
"""
Kiran Authentication Service MCP Server

面向软件：kiran-authentication-service

MCP tools 列表：
1. kiran_authentication_daemon_help_h - 执行 kiran-authentication-daemon -h 命令，显示帮助信息
   参数：无
   返回：统一JSON结构

2. kiran_authentication_daemon_help_long - 执行 kiran-authentication-daemon --help 命令，显示详细帮助
   参数：无
   返回：统一JSON结构

3. kiran_authentication_daemon_help_all - 执行 kiran-authentication-daemon --help-all 命令，显示完整帮助
   参数：无
   返回：统一JSON结构

4. kiran_authentication_daemon_version_v - 执行 kiran-authentication-daemon -v 命令，显示版本信息
   参数：无
   返回：统一JSON结构

5. kiran_authentication_daemon_version_long - 执行 kiran-authentication-daemon --version 命令，显示版本信息
   参数：无
   返回：统一JSON结构
"""

import subprocess
import json
from mcp.server.fastmcp import FastMCP, Context

mcp = FastMCP("Kiran Authentication Service MCP Server")

@mcp.tool()
def kiran_authentication_daemon_help_h():
    """
    执行 kiran-authentication-daemon -h 命令
    
    返回：
        JSON结构：{"success": bool, "command": str, "exit_code": int, "stdout": str, "stderr": str}
    """
    try:
        result = subprocess.run(
            ["kiran-authentication-daemon", "-h"],
            capture_output=True,
            text=True,
            timeout=30
        )
        return {
            "success": result.returncode == 0,
            "command": "kiran-authentication-daemon -h",
            "exit_code": result.returncode,
            "stdout": result.stdout,
            "stderr": result.stderr
        }
    except Exception as e:
        return {
            "success": False,
            "command": "kiran-authentication-daemon -h",
            "exit_code": -1,
            "stdout": "",
            "stderr": str(e)
        }

@mcp.tool()
def kiran_authentication_daemon_help_long():
    """
    执行 kiran-authentication-daemon --help 命令
    
    返回：
        JSON结构：{"success": bool, "command": str, "exit_code": int, "stdout": str, "stderr": str}
    """
    try:
        result = subprocess.run(
            ["kiran-authentication-daemon", "--help"],
            capture_output=True,
            text=True,
            timeout=30
        )
        return {
            "success": result.returncode == 0,
            "command": "kiran-authentication-daemon --help",
            "exit_code": result.returncode,
            "stdout": result.stdout,
            "stderr": result.stderr
        }
    except Exception as e:
        return {
            "success": False,
            "command": "kiran-authentication-daemon --help",
            "exit_code": -1,
            "stdout": "",
            "stderr": str(e)
        }

@mcp.tool()
def kiran_authentication_daemon_help_all():
    """
    执行 kiran-authentication-daemon --help-all 命令
    
    返回：
        JSON结构：{"success": bool, "command": str, "exit_code": int, "stdout": str, "stderr": str}
    """
    try:
        result = subprocess.run(
            ["kiran-authentication-daemon", "--help-all"],
            capture_output=True,
            text=True,
            timeout=30
        )
        return {
            "success": result.returncode == 0,
            "command": "kiran-authentication-daemon --help-all",
            "exit_code": result.returncode,
            "stdout": result.stdout,
            "stderr": result.stderr
        }
    except Exception as e:
        return {
            "success": False,
            "command": "kiran-authentication-daemon --help-all",
            "exit_code": -1,
            "stdout": "",
            "stderr": str(e)
        }

@mcp.tool()
def kiran_authentication_daemon_version_v():
    """
    执行 kiran-authentication-daemon -v 命令
    
    返回：
        JSON结构：{"success": bool, "command": str, "exit_code": int, "stdout": str, "stderr": str}
    """
    try:
        result = subprocess.run(
            ["kiran-authentication-daemon", "-v"],
            capture_output=True,
            text=True,
            timeout=30
        )
        return {
            "success": result.returncode == 0,
            "command": "kiran-authentication-daemon -v",
            "exit_code": result.returncode,
            "stdout": result.stdout,
            "stderr": result.stderr
        }
    except Exception as e:
        return {
            "success": False,
            "command": "kiran-authentication-daemon -v",
            "exit_code": -1,
            "stdout": "",
            "stderr": str(e)
        }

@mcp.tool()
def kiran_authentication_daemon_version_long():
    """
    执行 kiran-authentication-daemon --version 命令
    
    返回：
        JSON结构：{"success": bool, "command": str, "exit_code": int, "stdout": str, "stderr": str}
    """
    try:
        result = subprocess.run(
            ["kiran-authentication-daemon", "--version"],
            capture_output=True,
            text=True,
            timeout=30
        )
        return {
            "success": result.returncode == 0,
            "command": "kiran-authentication-daemon --version",
            "exit_code": result.returncode,
            "stdout": result.stdout,
            "stderr": result.stderr
        }
    except Exception as e:
        return {
            "success": False,
            "command": "kiran-authentication-daemon --version",
            "exit_code": -1,
            "stdout": "",
            "stderr": str(e)
        }

if __name__ == "__main__":
    mcp.run()